package com.xqzgj.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xqzgj.common.constant.UserConstants;
import com.xqzgj.common.utils.DateUtils;
import com.xqzgj.common.utils.StringUtils;
import com.xqzgj.system.domain.StockCategory;
import com.xqzgj.system.mapper.StockCategoryMapper;
import com.xqzgj.system.service.IStockCategoryService;

/**
 * 商品类别Service实现
 * 
 * @author xqzgj
 */
@Service
public class StockCategoryServiceImpl implements IStockCategoryService {
    @Autowired
    private StockCategoryMapper stockCategoryMapper;

    /**
     * 查询所有商品类别
     * 
     * @return 商品类别列表
     */
    @Override
    public List<StockCategory> selectStockCategoryAll() {
        return stockCategoryMapper.selectStockCategoryAll();
    }

    /**
     * 查询商品类别列表
     * 
     * @param stockCategory 商品类别
     * @return 商品类别
     */
    @Override
    public List<StockCategory> selectStockCategoryList(StockCategory stockCategory) {
        return stockCategoryMapper.selectStockCategoryList(stockCategory);
    }

    /**
     * 查询商品类别
     * 
     * @param id 商品类别主键
     * @return 商品类别
     */
    @Override
    public StockCategory selectStockCategoryById(Long id) {
        return stockCategoryMapper.selectStockCategoryById(id);
    }

    /**
     * 新增商品类别
     * 
     * @param stockCategory 商品类别
     * @return 结果
     */
    @Override
    public int insertStockCategory(StockCategory stockCategory) {
        stockCategory.setCreateTime(DateUtils.getNowDate());
        return stockCategoryMapper.insertStockCategory(stockCategory);
    }

    /**
     * 修改商品类别
     * 
     * @param stockCategory 商品类别
     * @return 结果
     */
    @Override
    public int updateStockCategory(StockCategory stockCategory) {
        stockCategory.setUpdateTime(DateUtils.getNowDate());
        return stockCategoryMapper.updateStockCategory(stockCategory);
    }

    /**
     * 批量删除商品类别
     * 
     * @param ids 需要删除的商品类别主键数组
     * @return 结果
     */
    @Override
    public int deleteStockCategoryByIds(Long[] ids) {
        return stockCategoryMapper.deleteStockCategoryByIds(ids);
    }

    /**
     * 删除商品类别信息
     * 
     * @param id 商品类别主键
     * @return 结果
     */
    @Override
    public int deleteStockCategoryById(Long id) {
        return stockCategoryMapper.deleteStockCategoryById(id);
    }

    /**
     * 校验商品类别名称是否唯一
     * 
     * @param stockCategory 商品类别信息
     * @return 结果
     */
    @Override
    public String checkCategoryNameUnique(StockCategory stockCategory) {
        Long categoryId = StringUtils.isNull(stockCategory.getId()) ? -1L : stockCategory.getId();
        StockCategory info = stockCategoryMapper.checkCategoryNameUnique(stockCategory.getCategoryName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != categoryId.longValue()) {
            return "1";
        }
        return "0";
    }

    /**
     * 校验商品类别编码是否唯一
     * 
     * @param stockCategory 商品类别信息
     * @return 结果
     */
    @Override
    public String checkCategoryCodeUnique(StockCategory stockCategory) {
        Long categoryId = StringUtils.isNull(stockCategory.getId()) ? -1L : stockCategory.getId();
        StockCategory info = stockCategoryMapper.checkCategoryCodeUnique(stockCategory.getCategoryCode());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != categoryId.longValue()) {
            return "1";
        }
        return "0";
    }
}